home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / DEVIRUS / DEVICE.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-06-27  |  2.6 KB  |  82 lines

  1. ;DEVICE.ASM is a simple device driver to illustrate the structure of
  2. ;a device driver. All it does is announce its presence when loaded.
  3.  
  4. ;(C) 1995 American Eagle Publications, Inc., All rights reserved.
  5.  
  6. .model tiny
  7. .code
  8.  
  9.         ORG     0
  10.  
  11. HEADER:
  12.         dd      -1              ;Link to next device driver
  13.         dw      0C840H          ;Device attribute word
  14.         dw      OFFSET STRAT    ;Pointer to strategy routine
  15.         dw      OFFSET INTR     ;Pointer to interrupt routine
  16.         db      'DEVICE'        ;Device name
  17.  
  18. RHPTR   dd      ?               ;pointer to request header, filled in by DOS
  19.  
  20. ;This is the strategy routine. Typically it just takes the value passed to it
  21. ;in es:bx and stores it at RHPTR for use by the INTR procedure. This value is
  22. ;the pointer to the request header, which the device uses to determine what is
  23. ;being asked of it.
  24. STRAT:
  25.         mov     WORD PTR cs:[RHPTR],bx
  26.         mov     WORD PTR cs:[RHPTR+2],es
  27.         retf
  28.  
  29. ;This is the interrupt routine. It's called by DOS to tell the device driver
  30. ;to do something. Typical calls include reading or writing to a device,
  31. ;opening it, closing it, etc.
  32. INTR:
  33.         push    bx
  34.         push    si
  35.         push    di
  36.         push    ds
  37.         push    es
  38.         push    cs
  39.         pop     ds
  40.         les     di,[RHPTR]      ;es:di points to request header
  41.         mov     al,es:[di+2]    ;get command number
  42.  
  43.         or      al,al           ;command number 0? (Initialize device)
  44.         jnz     INTR1           ;nope, handle other commands
  45.         call    INIT            ;yes, go initialize device
  46.         jmp     INTRX           ;and exit INTR routine
  47.  
  48. INTR1:  call    NOT_IMPLEMENTED ;all other commands not implemented
  49.  
  50. INTRX:  pop     es
  51.         pop     ds
  52.         pop     di
  53.         pop     si
  54.         pop     bx
  55.         retf
  56.  
  57. ;Device initialization routine, Function 0. This just displays HELLO_MSG using
  58. ;BIOS video and then exits.
  59. INIT:
  60.         mov     si,OFFSET HELLO_MSG
  61. INITLP: lodsb
  62.         or      al,al
  63.         jz      INITX
  64.         mov     ah,0EH
  65.         int     10H
  66.         jmp     INITLP
  67. INITX:  mov     WORD PTR es:[di+14],OFFSET END_DRIVER
  68.         mov     WORD PTR es:[di+16],cs  ;indicate end of driver here
  69.         xor     ax,ax           ;zero ax to indicate success and exit
  70.         retn
  71.  
  72. HELLO_MSG       DB      'DEVICE 1.00 Says "Hello!"',0DH,0AH,0
  73.  
  74. ;This routine is used for all non-implemented functions.
  75. NOT_IMPLEMENTED:
  76.         xor     ax,ax           ;zero ax to indicate success and exit
  77.         retn
  78.  
  79. END_DRIVER:                     ;label to identify end of device driver
  80.  
  81.         END     STRAT
  82.